# --*-- coding:utf-8 --*--
import sys
import platform
import datetime
import requests
import json
import re
import tornado
import tornado.web
import tornado.ioloop
import tornado.httpserver
import BaseHTTPServer
from converter import Converter


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        target = self.get_argument("target")
        if target == "jp2ch":
            jp_str = self.get_argument("jp_str").strip() + '\n'
            print jp_str
            res = Converter.jp_to_ch(Converter.chinese_to_kana(jp_str))
            self.write(res)
        if target == "jp2rome":
            str = self.get_argument("jp_str").strip()
            res = Converter.jp_to_rome(Converter.chinese_to_kana(unicode(str)))
            self.write(res)


    def set_default_headers(self):
        self.set_header('Access-Control-Allow-Origin', '*')
        self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
        self.set_header('Access-Control-Max-Age', 1000)
        self.set_header('Access-Control-Allow-Headers', '*')
        self.set_header('Content-type', 'application/json')


application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()





